#include <cstdio>
#include <vector>

#define MAX_SIZE 1000010

using namespace std;

int n;  // 顶点数
vector<int> adj[MAX_SIZE];  // 顶点的邻接表
bool Hash[MAX_SIZE] = {false};
bool visited[MAX_SIZE] = {false};

void dfs(int u) {
	visited[u] = true;
	for (int i = 0; i < adj[u].size(); ++i) {
		int v = adj[u][i];
		if (!visited[v]) dfs(v);
	}
}

void dfsTravel() {
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (Hash[i] && !visited[i]) {
			dfs(i);
			++ans;
		}
	}

	printf("%d\n", ans);
	return;
}

int main() {
	int x, y;

	while (scanf("%d %d", &x, &y) == 2) {
		if (x > n) n = x;
		if (y > n) n = y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		Hash[x] = true;
		Hash[y] = true;
	}

	dfsTravel();
	return 0;
}